<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>二维码</title>
</head>
<style>
    body, html {
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100%;
        background-color: #ec3436;
    }
</style>
<body>
	<audio id="myaudio" src="/img/back.mp3" controls="controls" loop="true" hidden="true" >
</audio>
<div style="width: 100%;height: 100%;background-image: url('/img/phone.png');background-position-x: center;background-size: contain;background-position-y: bottom;background-repeat: no-repeat">
    <div style="width: 100%;height: 100%;background-image: url('/img/money.png');background-position-x: center;background-size: contain">
        <div style="width: 100%;height: 100%;background-image: url('/img/hint.png');background-size: contain;background-position-y: bottom;background-repeat: no-repeat">
        {{/*<div style="width:100%;height:100%;background-image: url('/img/mobile.png');background-position-x: center;background-position-y:40%;background-size: 40%;background-repeat: no-repeat">*/}}
        {{/**/}}
        {{/*</div>*/}}
            <div id="qrcode"
                 style="width: 40%;height: auto;margin-left: auto;margin-right:auto;padding-top:50vw;text-align: center;"></div>
        </div>
    </div>
</div>
<script src="/js/model/jquery-1.8.0.min.js"></script>
<script src="/js/jquery.qrcode.min.js"></script>
<script src="/js/reconnecting-websocket.js"></script>
<script>
    var str = "http://tmp.hamer.xin/user/scan?Id={{.Id}}&token={{.token}}";
    var width = $('#qrcode').width();
    console.log(str);
    $('#qrcode').qrcode({width: width, height: width, text: str});
    setInterval(function () {
        updateToken();
    }, 60000);
    var updateToken = function () {
        $.post("/device/refreshtoken", function (data) {
            console.log(data);
            if (data.Code == 0) {
                console.log(data.Data);
                str = "http://tmp.hamer.xin/user/scan?Id={{.Id}}&token=" + data.Data;
                console.log(str);
                $("#qrcode canvas").remove();
                $('#qrcode').qrcode({width: width, height: width, text: str});
            }
        })
    }
</script>
{{/*<script src="https://cdn.wilddog.com/sdk/js/2.5.8/wilddog.js"></script>*/}}
{{/*<script type="text/javascript">*/}}
    {{/*var config = {*/}}
        {{/*syncURL: "https://wild-ox-5743.wilddogio.com" //输入节点 URL*/}}
    {{/*};*/}}
    {{/*wilddog.initializeApp(config);*/}}

    {{/*wilddog.sync().ref('wheel').on("value", function (snapshot) {*/}}
        {{/*console.log(snapshot.val());*/}}
        {{/*console.log("hi");*/}}
        {{/*if (snapshot.val() === {{.Id}}) {*/}}
            {{/*window.location.href = "/device/prisepage";*/}}
        {{/*}*/}}
    {{/*});*/}}
{{/*</script>*/}}
<script>
	window.history.forward(-1);
	function prevent (e) {
　　e.preventDefault();
}
$('body').on('touchmove', prevent);
	function autoPlay(){
		var myAuto = document.getElementById('myaudio');
		myAuto.play();
	}
	autoPlay();
    var socket;

    $(document).ready(function () {
        // Create a socket
        socket = new ReconnectingWebSocket('ws://' + window.location.host + '/device/join?Id={{.Id}}');
        // Message received on the socket
        socket.onmessage = function (event) {
            var data = JSON.parse(event.data);
            console.log(data);
            switch (data.Type) {
                case 0: // JOIN
                    console.log(data.User,data.Content);
                    break;
                case 1: // LEAVE
                    console.log(data.User,data.Content);
                    break;
                case 2: // MESSAGE
                    if (data.User=={{.Id}} && data.Content=={{.Id}}){
                        window.location.href = "/device/prisepage";
                    }else {
                        console.log(data.User,data.Content);
                    }
                    break;
            }
        };

/*        // Send messages.
        var postConecnt = function () {
            var uname = $('#uname').text();
            var content = $('#sendbox').val();
            socket.send(content);
            $('#sendbox').val("");
        }

        $('#sendbtn').click(function () {
            postConecnt();
        });*/
    });
</script>
</body>
</html>
